﻿using Architecture.Logging.Agent.Services.Admin;
using Microsoft.Owin.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Architecture.Logging.Agent.Services
{
    public class WebApiListener
    {

        private IDisposable server;

        public void Start()
        {
            string baseAddress = "http://localhost:9000/";

            // Start OWIN host 
            server = WebApp.Start<WebapiStartup>(url: baseAddress);

            //string baseAddress = "http://localhost:9000/";

            //// Start OWIN host 
            //using (WebApp.Start<WebapiStartup>(url: baseAddress))
            //{
            //    // Create HttpCient and make a request to api/values 
            //    HttpClient client = new HttpClient();

            //    var response = client.GetAsync(baseAddress + "api/Sources/7e8ad27f-b271-4ea2-a783-a47bde29143b").Result;

            //    Console.WriteLine(response);
            //    Console.WriteLine(response.Content.ReadAsStringAsync().Result);


            //    var result = response.Content.ReadAsAsync<TraceProvider>().Result;
            //    result.Enabled = false;

            //    var responseUpdate = client.PutAsJsonAsync<TraceProvider>(baseAddress + "api/Sources/", result).Result;

            //    Console.WriteLine(responseUpdate);
            //    Console.WriteLine(responseUpdate.Content.ReadAsStringAsync().Result);

            //    var responseAfterUpdate = client.GetAsync(baseAddress + "api/Sources/7e8ad27f-b271-4ea2-a783-a47bde29143b").Result;

            //    Console.WriteLine(responseAfterUpdate);
            //    Console.WriteLine(responseAfterUpdate.Content.ReadAsStringAsync().Result);


            //    var newprovider = new TraceProvider()
            //    {
            //        Name = "Microsoft-Windows-IIS-W3SVC-PerfCounters",
            //        Id = Guid.Parse("90303B54-419D-4081-A683-6DBCB532F261"),
            //        Enabled = false
            //    };

            //    var responseAdd = client.PostAsJsonAsync<TraceProvider>(baseAddress + "api/Sources/", newprovider).Result;

            //    Console.WriteLine(responseAdd);
            //    Console.WriteLine(responseAdd.Content.ReadAsStringAsync().Result);

            //    var responseAfterAdd = client.GetAsync(baseAddress + "api/Sources/").Result;

            //    Console.WriteLine(responseAfterAdd);
            //    Console.WriteLine(responseAfterAdd.Content.ReadAsStringAsync().Result);

            //}

            //Console.ReadLine();
            //return;



        }

        public void Stop()
        {
            server.Dispose();
        }
    }
}
